#include "Logic/SkeletalInstanceManagerActor.h"

#include "SkelotAnimCollection.h"
#include "SkelotComponent.h"


void ASlgSkeletalInstanceActor::SetComponentClass(TSubclassOf<USkelotComponent> InComponentClass)
{
	ComponentClass = InComponentClass;
}

USkelotComponent* ASlgSkeletalInstanceActor::FindComponent(FSkeletalInstancedProxyAbstract* Proxy)
{
	if(!Proxy)
		return nullptr;
	const FSkeletalInstanceKey& Key = Proxy->GetInstanceKey();
	if(auto Value = ComponentMap.Find(Key))
	{
		return *Value;
	}
	USkelotAnimCollection* AnimCollection = Proxy->GetAnimCollection();
	if(!AnimCollection)
	{
		return nullptr;
	}
	USkelotComponent* Component = NewObject<USkelotComponent>(this, Key.GetFName());
	Component->AnimCollection = AnimCollection;
	Component->bReceivesDecals = false;
	Component->bUseFixedInstanceBound = true;
	Component->InstanceDefaultAttachIndex = 0;
	Component->bRenderCustomDepth = Key.bRenderCustomDepth;

	FSkelotSubmeshSlot SubMeshSlot;
	SubMeshSlot.SkeletalMesh = Proxy->GetSkeletalMesh();
	if(SubMeshSlot.SkeletalMesh)
	{
		SubMeshSlot.Name = SubMeshSlot.SkeletalMesh->GetFName();
	}
	Component->AddSubmesh(SubMeshSlot);
	Component->RegisterComponent();
	AddInstanceComponent(Component);
	ComponentMap.Add(Key, Component);
	return Component;
}

void ASlgSkeletalInstanceActor::BeginUpdateInstancedData()
{
	
}

void ASlgSkeletalInstanceActor::UpdateInstancedDataEnd()
{
	
}